{extend name="platform/base" /} {block name="main"}
<div class="row padder-v">
	<div class="col-sm-4">
		<a href="PLATFORM_MAIN/Goods/addGoodsCategory"
			class="btn btn-sm btn-primary"><i class="fa fa-plus"></i> 添加商品分类</a>
	</div>
</div>
<section class="panel panel-default">
	<table class="table table-striped b-t b-light text-sm">
		<thead>
			<tr>
				<th width="10"></th>
				<th width="80">排序</th>
				<th class="center">商品分类</th>
				<th class="center">商品分类简称</th>
				<th class="center">关联类型</th>
				<th class="center">是否显示</th>
				<th class="center" width="100">操作</th>
			</tr>
		</thead>
		<tbody>
			{foreach name="category_list" item="v1"}
			<tr class="pid_0" style="height: 30px;">
				<td>{if condition="$v1['child_list'] neq array()"}<a
					href="javascript:;" onclick="tab_switch({$v1['category_id']})"
					class="tab_jia_{$v1['category_id']}" style="display: block;"><i
						class="fa fa-plus"></i></a><a href="javascript:;"
					onclick="tab_switch({$v1['category_id']})"
					class="tab_jian_{$v1['category_id']}" style="display: none;"><i
						class="fa fa-minus"></i></a> {/if}
				</td>
				<td><input type="text" class="form-control"
					fieldid="{$v1['category_id']}" fieldname="sort"
					value="{$v1['sort']}" size="1"></td>
				<td>
					<div class="col-md-12">
						<input type="text" class="form-control"
							fieldid="{$v1['category_id']}" fieldname="category_name"
							value="{$v1['category_name']}">
					</div>
				</td>
				<td>
					<input type="text" class="form-control" fieldid="{$v1['category_id']}" fieldname="short_name" value="{$v1['short_name']}">
				</td>
				<td class="center">
					<a>{$v1['attr_name']}</a>
				</td>
				<td class="center"><a href="#"
					class="{$v1['is_visible'] ? 'active' : ''}" data-toggle="class"
					onclick="changeField({$v1['category_id']}, 'is_visible', {$v1['is_visible'] ? 0 : 1});"><i
						class="fa fa-check text-success text-active"></i><i
						class="fa fa-times text-danger text"></i></a></td>
				<td class="center"><a
					href="PLATFORM_MAIN/goods/updategoodscategory?category_id={$v1['category_id']}">修改</a>
					<a href="javascript:void(0);"
					onclick="delCategory({$v1['category_id']})">删除</a></td>
			</tr>
			{foreach name="v1['child_list']" item="v2"}
			<tr class="pid_{$v1['category_id']}"
				style="height: 30px; display: none;">
				<td>{if condition="$v2['child_list'] neq array()"}<a
					href="javascript:;" onclick="tab_switch({$v2['category_id']})"
					class="tab_jian_{$v2['category_id']}" style="display: block;"><i
						class="fa fa-minus"></i></a><a href="javascript:;"
					onclick="tab_switch({$v2['category_id']})"
					class="tab_jia_{$v2['category_id']}" style="display: none;"><i
						class="fa fa-plus"></i></a> {/if}
				</td>
				<td><input type="text" class="form-control"
					fieldid="{$v2['category_id']}" fieldname="sort"
					value="{$v2['sort']}" size="1"></td>
				<td><div class="col-md-1" style="padding-right:0px;"></div>
					<div class="col-md-11">
						<input type="text" class="form-control"
							fieldid="{$v2['category_id']}" fieldname="category_name"
							value="{$v2['category_name']}">
					</div></td>

				<td><input type="text" class="form-control"
					fieldid="{$v2['category_id']}" fieldname="short_name"
					value="{$v2['short_name']}"></td>
				<td class="center">
					{$v2['attr_name']}
				</td>	
				<td class="center"><a href="#"
					class="{$v2['is_visible'] ? 'active' : ''}" data-toggle="class"
					onclick="changeField({$v2['category_id']}, 'is_visible', {$v2['is_visible'] ? 0 : 1});"><i
						class="fa fa-check text-success text-active"></i><i
						class="fa fa-times text-danger text"></i></a></td>
				<td class="center"><a
					href="PLATFORM_MAIN/goods/updategoodscategory?category_id={$v2['category_id']}">修改</a>
					<a href="javascript:void(0);"
					onclick="delCategory({$v2['category_id']})">删除</a></td>
			</tr>
			{foreach name="v2['child_list']" item="v3"}
			<tr class="pid_{$v2['category_id']} pid_{$v1['category_id']}"
				style="height: 30px; display: none;">
				<td><label></td>
				<td><input type="text" class="form-control"
					fieldid="{$v3['category_id']}" fieldname="sort"
					value="{$v3['sort']}" size="1"></td>
				<td>
					<div class="col-md-2"></div>
					<div class="col-md-10">
						<input type="text" class="form-control"
							fieldid="{$v3['category_id']}" fieldname="category_name"
							value="{$v3['category_name']}">
					</div>
				</td>

				<td><input type="text" class="form-control"
					fieldid="{$v3['category_id']}" fieldname="short_name"
					value="{$v3['short_name']}"></td>
				<td class="center">
					{$v3['attr_name']}
				</td>	
				<td class="center"><a href="#"
					class="{$v3['is_visible'] ? 'active' : ''}" data-toggle="class"
					onclick="changeField({$v3['category_id']}, 'is_visible', {$v3['is_visible'] ? 0 : 1});"><i
						class="fa fa-check text-success text-active"></i><i
						class="fa fa-times text-danger text"></i></a></td>
				<td class="center"><a
					href="PLATFORM_MAIN/goods/updategoodscategory?category_id={$v3['category_id']}">修改</a>
					<a href="javascript:void(0);"
					onclick="delCategory({$v3['category_id']})">删除</a></td>
			</tr>
			{/foreach} {/foreach} {/foreach}
		</tbody>
	</table>
</section>

{/block} {block name="script"}
<script type="text/javascript">
$("table input").change(function(){
	var fieldid = $(this).attr('fieldid');
	var fieldname = $(this).attr('fieldname');
	var fieldvalue = $(this).val();
	changeField(fieldid,fieldname,fieldvalue);
});
function changeField(fieldid,fieldname,fieldvalue){
	$.ajax({
		type:"post",
		url:"PLATFORM_MAIN/goods/modifygoodscategoryfield",
		data:{'fieldid':fieldid,'fieldname':fieldname,'fieldvalue':fieldvalue},
		async:true,
		success: function (data) {
			if(data['code'] <= 0){
				showMessage('error',data['message']);
			}
		}
	});
}
	function tab_switch(module_id){
		if($(".pid_"+module_id).css('display') != 'none'){
			$(".tab_jian_"+module_id).hide();
			$(".tab_jia_"+module_id).show();
			$(".pid_"+module_id).hide(300);
		}else{
			$(".tab_jian_"+module_id).show();
			$(".tab_jia_"+module_id).hide();
			$(".pid_"+module_id).show(500);
		}
	}
	/* 删除分类 */
	function delCategory(category_id) {
		$( "#dialog" ).dialog({
            buttons: {
                "确定": function() {
                    $(this).dialog('close');
					$.ajax({
						type : "post",
						url : "PLATFORM_MAIN/goods/deletegoodscategory",
						data : {
							'category_id' : category_id
						},
						async : true,
						success : function(data) {
							if(data['code'] > 0){
								showMessage('success', data["message"],'PLATFORM_MAIN/goods/goodscategorylist');
							}else{
								showMessage('error', data["message"]);
							}
						}
					});
                },
                "取消,#e57373": function() {
                    $(this).dialog('close');
                }
            },
            contentText:"你确定删除吗？",
            title:"消息提醒"
        });
	}
</script>
{/block}
